package app.im;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.menhoo.toollibrary.common.utils.StringUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import app.AddressBookDeptSelector;
import app.ContactInfo;
import application.HttpUrlConstant;
import custom.PinnedSectionListView;
import custom.kyletterfilter.KyLetterfilter;
import mainUI.AppActivity;
import menhoo.com.i8officelibrary.R;
import model.EmployeeItemDBModel;

/**
 * Created by ThinkPad on 2017/5/10.
 */

public class IMAddChat extends AppActivity {

    private IMAddChatPersenter persenter;

    private PinnedSectionListView listview;
    private IMAddChatListAdapter adapter;
    private List<EmployeeItemDBModel> datas;
    private HorizontalScrollView listselected;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        persenter = new IMAddChatPersenter(this);
        setContentView(R.layout.activity_addchat);
        persenter.getIntentData(getIntent());

        initView();
        persenter.getFirstListData();
    }

    private void initView(){
        listview = (PinnedSectionListView) findViewById(R.id.listview);
        listselected = (HorizontalScrollView) findViewById(R.id.listselected);

        datas = new ArrayList<EmployeeItemDBModel>();
        adapter = new IMAddChatListAdapter(this, datas);
        listview.setAdapter(adapter);


        listview.setShadowVisible(false);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                //如果id是-1说明这个是Header 或者  Footer
                if (id == -1) {
                    return;
                }
                EmployeeItemDBModel item = (EmployeeItemDBModel) parent.getAdapter().getItem(position);

                if (item.type == EmployeeItemDBModel.ITEM) {

                    if (item.DeptID == null || item.DeptID.equalsIgnoreCase("")) {
                        //empl
                        Intent it = new Intent(IMAddChat.this, ContactInfo.class);
                        it.putExtra("emplID", item.EmplID);
                        startActivity(it);
                    } else {
                        //dept
                        persenter.getListData(item.DeptID);
                    }
                }
            }
        });
    }


    public void dataNotifyDataSetChanged(List<EmployeeItemDBModel> data) {
        adapter.changeData(data);
    }
}
